home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Workspace / ObjInspector / Source / ObjInspector.m < prev    next >
Text File  |  1995-06-12  |  3KB  |  110 lines

  1. //----------------------------------------------------------------------------------------------------
  2. //
  3. //    ObjInspector
  4. //
  5. //    Inherits From:        WMInspector
  6. //
  7. //    Declared In:        ObjInspector.h
  8. //
  9. //    Disclaimer
  10. //
  11. //        You may freely copy, distribute and reuse this software and its
  12. //        associated documentation. I disclaim any warranty of any kind, 
  13. //        expressed or implied, as to its fitness for any particular use.
  14. //
  15. //----------------------------------------------------------------------------------------------------
  16.  
  17. #import "ObjInspector.h"
  18.  
  19. #define NM        "nm"
  20. #define AWK_TR        "| awk '$2 == \"t\" || $2 == \"T\" {print $3,$4}' | tr -d '[]'"
  21. #define OUT_OF_MEMORY    "Out of Memory!"
  22. #define PROCESS_ERROR    "Unable to open process stream!"
  23.  
  24. @implementation ObjInspector
  25.  
  26. static id     _SELF = nil;
  27.  
  28. //----------------------------------------------------------------------------------------------------
  29. //  Private Methods
  30. //----------------------------------------------------------------------------------------------------
  31. - _alert: (STR) errorMessage
  32. {
  33.     NXRunAlertPanel (NULL, "%s", NULL, NULL, NULL, errorMessage);
  34.     return self;
  35. }
  36.  
  37.     
  38. - _getTableOfContents
  39. {
  40.     //  Get Objects text symbols by sending NM, AWK_TR command.
  41.     //  Response stream will be read to populate browser (in brower:fillMatrix:inColumn).
  42.     
  43.     STR    command;
  44.     FILE    *responsePipe;
  45.     NXStream *responseStream;
  46.     char     currentPath [MAXPATHLEN+1];
  47.     id    font;
  48.         
  49.     [self selectionPathsInto:currentPath separator:'\0'];
  50.     
  51.     if (! (command = malloc (strlen (NM) + strlen (currentPath) + strlen (AWK_TR) + 3)))
  52.         {
  53.         [self _alert: OUT_OF_MEMORY];
  54.         return nil;
  55.         }
  56.         
  57.     sprintf (command, "%s %s %s", NM, currentPath, AWK_TR);
  58.  
  59.     if (! (responsePipe = popen (command, "r")))
  60.         {
  61.         if (command) free (command);
  62.         [self _alert: PROCESS_ERROR];
  63.         return nil;
  64.         }        
  65.  
  66.     if (command) free (command);
  67.  
  68.     //  Populate Table Of Contents ScrollView text with formatted command response.
  69.     //  Set the font here (fixed font for even column alignment).
  70.  
  71.      font = [Font newFont: "Courier" size: 10];
  72.     responseStream = NXOpenFile (fileno (responsePipe), NX_READONLY);
  73.     [textView readText:responseStream];
  74.     NXClose (responseStream);
  75.     pclose (responsePipe);
  76.     if (font) [font free];
  77.     return self;
  78. }
  79.  
  80.  
  81. //----------------------------------------------------------------------------------------------------
  82. //  WMInspector Methods
  83. //----------------------------------------------------------------------------------------------------
  84. + new
  85. {
  86.     //  Required/called by WM.  Only allow one instance...
  87.     
  88.         char     path[MAXPATHLEN+1];
  89.         id         bundle;
  90.  
  91.         if (_SELF) return _SELF;
  92.  
  93.         _SELF = self = [super new];
  94.  
  95.         if ( ! (bundle = [NXBundle bundleForClass:[ObjInspector class]] ) ) return nil;          
  96.     if ( ! [bundle getPath:path forResource:"ObjInspector" ofType:"nib"] ) return nil;
  97.         [NXApp loadNibFile:path owner:self  withNames:NO fromZone:[self zone]];
  98.  
  99.      return _SELF;
  100. }
  101.  
  102.  
  103. - revert: sender
  104. {
  105.     //  Called by WM when file selection is type we inspect.    
  106.     [self _getTableOfContents];
  107.     return [super revert: sender];
  108. }
  109.  
  110. @end